package com.maimao.core.utils;

import com.maimao.core.constant.Constants;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @author MaoLin Wang
 * @date 2020/12/13 10:20 上午
 */
public class MaiMaoStringUtil {

    /**
     * 集合按sep分割成字符串
     */
    public static String join2String(List<String>list,String sep){
        if (list==null || list.size()<=0){
            return Constants.EMPTY;
        }
        StringBuilder sb=new StringBuilder();
        for (String str : list) {
            String trim = str.trim();
            if (StringUtils.isEmpty(trim)){
                continue;
            }
            sb.append(trim).append(sep);
        }
        String res = sb.toString();
        return StringUtils.substringBeforeLast(res,sep);
    }
}
